package com.imooc.servlet.pattern;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 获取当前请求的URL
 * 
 * 比传统的按照URl参数传递更加实用
 * 
 */
@WebServlet("/pattern/*")
public class PatternServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//查询员工的基本信息
		//获取当前请求的URL
		String url = request.getRequestURI();
		System.out.println(url);
		String id = url.substring(url.lastIndexOf("/")+1);
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(id);
		if(id.equals("1")) {
			out.println("张三");
		}else if(id.equals("2")){
			out.println("李四");
		}else {
			out.println("其他员工");
		}
	}

}
